package org.finesys.system.service.impl;

import cn.hutool.core.lang.Dict;
import lombok.RequiredArgsConstructor;
import org.finesys.common.security.core.module.AuthUser;
import org.finesys.common.security.core.util.SecurityUtils;
import org.finesys.system.service.SysThirdOperateService;
import org.finesys.system.service.SysThirdService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class SysThirdServiceImpl implements SysThirdService {

    private final List<SysThirdOperateService> sysThirdOperateServiceList;


    @Override
    public Dict bindInfo() {
        AuthUser authUser = SecurityUtils.getUser();
        Long userId = authUser.getUserId();
        Dict dict = Dict.create();
        sysThirdOperateServiceList.stream().forEach(t -> {
            dict.put(t.support(), t.getBindInfo(userId));
        });
        return dict;
    }

    @Override
    public boolean unbind(String type) {
        AuthUser authUser = SecurityUtils.getUser();
        Long userId = authUser.getUserId();
        sysThirdOperateServiceList.stream().filter(t -> t.support().equals(type))
                .forEach(t -> {
                    t.unbind(userId);
                });
        return true;
    }
}
